package com.huarui.partner.action;

import java.util.HashMap;
import java.util.Map;

import org.ewaf.framework.action.BaseAction;

import com.huarui.partner.model.Partner;
import com.huarui.partner.service.PartnerService;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;

/**
 * 
 * @author ycf
 *
 */
public class PartnerQueryAction extends BaseAction{

	private static final long serialVersionUID = 7382638281085123074L;
	
	public static final String MESS = "mess";
	
	private PartnerService partnerService;
	
	private String id;
	
	private Map<String, Object> mesMap;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	public Map<String, Object> getMesMap() {
		return mesMap;
	}

	public void setMesMap(Map<String, Object> mesMap) {
		this.mesMap = mesMap;
	}

	public void setPartnerService(PartnerService partnerService) {
		this.partnerService = partnerService;
	}

	public String getPartnerByIdAndOwnerId() {
		if(id == null || id.trim().equals("")) {
			mesMap = new HashMap<String, Object>();
			mesMap.put("result", "error");
			return MESS;
		}
		mesMap = partnerService.getPartnerByIdAndOwnerId(id);
		mesMap.put("result", "ok");
		return MESS;
	}

	public String validateOtherPartner() {
		if(id == null || id.trim().equals("")) {
			mesMap = new HashMap<String, Object>();
			mesMap.put("result", "error");
			return MESS;
		}
		mesMap = partnerService.checkPartnerById(id);
		
		return MESS;
		
	}
	
	public String getOtherPartnerByCompId() {
		mesMap = new HashMap<String, Object>();
		if(id == null || id.trim().equals("")) {
			mesMap.put("result", "error");
			return MESS;
		}
		
		mesMap.put("ownerId", id);
		mesMap.put("companyId", UserHolder.getCurrentSessionMessage().getCompanyId());
		mesMap.put("isDelete", 0);
		mesMap.put("relation", Partner.REALATION_CUSTOMER);
		Partner p = partnerService.findPartnerByOwnerId(mesMap);
		
		mesMap.clear();
		if(p != null) {
			mesMap.put("discount", p.getDiscount());
		} else {
			
		}
		
		return MESS;
	}
}
